﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BusinessObjects.BO_GetObjects;
using LibraryO2S;

public partial class controls_admin_ViewVote : System.Web.UI.UserControl
{
    protected int vid;
    private DataTable objDT;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            loadVote();
    }
    private void loadVote()
    {
        try
        {
            objDT = BO_VoteQuestions.SelectTop(1, 1);
            if (objDT != null && objDT.Rows.Count > 0)
            {
                string VOTE_ANSWERS = objDT.Rows[0]["VOTE_ANSWERS"].ToString();
                vid = Convert.ToInt32(objDT.Rows[0]["VOTE_ID"].ToString());
                divQues.InnerText = objDT.Rows[0]["VOTE_QUESTION"].ToString();
                string[] listVote = VOTE_ANSWERS.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                DataTable dtVote = new DataTable("Vote");
                dtVote.Columns.Add("TOTALVOTE", typeof(String));
                dtVote.Columns.Add("ANSWER", typeof(String));
                dtVote.Columns.Add("ANSWER_ENG", typeof(String));
                dtVote.Columns.Add("NUMBER", typeof(String));
                dtVote.Columns.Add("RATE", typeof(String));
                foreach (string perVote in listVote)
                {
                    string[] allInfo = perVote.Split(new string[] { ":*:" }, StringSplitOptions.None);
                    DataRow drVote = dtVote.NewRow();
                    drVote["TOTALVOTE"] = allInfo[0];
                    drVote["ANSWER"] = allInfo[1];
                    drVote["ANSWER_ENG"] = allInfo[2];
                    drVote["NUMBER"] = allInfo[3];
                    drVote["RATE"] = allInfo[4];
                    dtVote.Rows.Add(drVote);
                }
                rptVote.DataSource = dtVote;
                rptVote.DataBind();
            }
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = O2S_Message.Error("Lỗi", "Phát hiện lỗi :<br />" + ex.Message);
        }
    }
}
